﻿using System;
using System.Linq;
using System.Reflection;
using K9Nano.Dependency;
using K9Nano.Remoting;

namespace K9Nano.Configuration.Startup
{
    public sealed class StartupConfiguration
    {
        public IDependencyConvention DependencyConvention { get; set; }

        public Func<TypeInfo, bool> ClassFilterFactory { get; set; }

        public IMultiTenancyConfig MultiTenancyConfig { get; }

        public ISettingDefinitionManager SettingDefinitionManager { get; }

        public IApiInfo ApiInfo { get; set; }

        private StartupConfiguration()
        {
            DependencyConvention = new DefaultDependencyConvention();
            SettingDefinitionManager = new SettingDefinitionManager();
            ClassFilterFactory = x =>
                x.IsClass
                && !x.IsAbstract
                && x.GetInterfaces()
                    .Any(i => i.Name == nameof(ISingletonDependency)
                              || i.Name == nameof(ITransientDependency)
                              || i.Name == nameof(IScopedDependency));
            MultiTenancyConfig = new MultiTenancyConfig();
            ApiInfo = new ApiInfo();

        }

        public static StartupConfiguration Global = new StartupConfiguration();
    }
}